package com.chb.friend1错误的combiner;
import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
/**
 *Combiner是将mapper的输出进行合并， 
 *并不改变输入输出的类型。
 *所以此处Combiner是错误的
 */
public class FofCombiner extends Reducer<Fof, IntWritable, Text, Text>{

	@Override
	protected void reduce(Fof key, Iterable<IntWritable> values, Context context)
			throws IOException, InterruptedException { 
		int sum = 0;
		for (IntWritable iw : values) {
			if (iw.get() == 0) {//出现值为0的fof为直接好友，不用统计了
				return;
			}
			sum += iw.get();
		}
		//输出Fof ab和ba
		String a = key.toString().split("\t")[1];
		String b = key.toString().split("\t")[0];
		context.write(new Text(a), new Text(b+"\t"+1));
		context.write(new Text(b), new Text(a+"\t"+1));

	}
}
